/*******************************************************************************
* Purpose: Pull variables from IHDP ASCII files (available through ICPSR) and 
*		   save the result as dta
* 
* Dependencies:
*   Input: ASCII data files and scripts in ihdp/ *.do 
*   Output: Stata files with raw IHDP data
*
* Notes: Description of output files could be found in README.md
*******************************************************************************/

clear all
set more off

global projects: env projects

cd "$projects/ece_parenting/scripts/1-data_read_in/ihdp"

local workdir "$projects/ece_parenting/scripts/1-data_read_in/ihdp"
local dofiles: dir "`workdir'" files "*.do"

foreach file of local dofiles {
    display _newline(2) "===> Now running: `file'" _newline(2)
	capture mkdir "$storage/ece_parenting/raw_data"
	qui do "`file'"
	local filename = upper(substr("`file'", 1, length("`file'") - 3))
    save "$storage/ece_parenting/raw_data/`filename'.dta"
}

display _newline(2) "===> All do-files have been executed" _newline(2)
